#ifndef VIDEORECORDTHREAD_H
#define VIDEORECORDTHREAD_H

#include <QObject>
#include "FFThread.h"
#include "FFString.h"

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavfilter/avfilter.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libpostproc/postprocess.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
}

enum VideoRecordState {
    VideoRecording,
    VideoRecordEnd,
    VideoRecordFail
};

struct VideoRecordOption {

    int width = 1920;

    int height = 1080;

    AVPixelFormat pixleFormat = AV_PIX_FMT_UYVY422;

    int frameRate = 30;

    AVDictionary* optionDict() {
        AVDictionary *options = nullptr;
        FFString video_size = FFString();
        video_size.appendInt(width);
        video_size.append("x");
        video_size.appendInt(height);
        av_dict_set(&options, "video_size", video_size.toStdString().c_str(), 0);

        switch (pixleFormat) {
        case AV_PIX_FMT_UYVY422:
        {
            av_dict_set(&options, "pixel_format", "uyvy422", 0);
        }
        break;
        default:
            break;
        }
        av_dict_set(&options, "framerate", std::to_string(frameRate).c_str(), 0);
        return options;
    }

};

class VideoRecordThread : public FFThread
{
    Q_OBJECT
public:

    void run();

    QString recordPath;

    VideoRecordOption *recordOption = new VideoRecordOption();

    ~VideoRecordThread();

signals:
    void recordState(VideoRecordState state);

};

#endif // VIDEORECORDTHREAD_H
